'use strict';
var app = getApp();

function saveNumber(radio_number, switch_number) {
    var radio = radio_number;
    var sw = switch_number;
    if (radio != undefined) {
        if (radio == '手机号') {
            if (sw == true) {
                if ((app.globalData.user_form[0].edit == false) || (app.globalData.user_form[0].edit == undefined)) { //新建一项
                    app.globalData.user_form[app.globalData.user_form.length] = {};
                    app.globalData.user_form[app.globalData.user_form.length - 1].item = 'number';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_name = '手机号';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_nec = true;
                } else if (app.globalData.user_form[0].edit == true) { //编辑旧的
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name = '手机号';
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec = true;
                }
            } else if ((sw == false) || (sw == undefined)) {
                if ((app.globalData.user_form[0].edit == false) || (app.globalData.user_form[0].edit == undefined)) {
                    app.globalData.user_form[app.globalData.user_form.length] = {};
                    app.globalData.user_form[app.globalData.user_form.length - 1].item = 'number';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_name = '手机号';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_nec = false;
                } else if (app.globalData.user_form[0].edit == true) {
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name = '手机号';
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec = false;
                }
            }
        } else if (radio == 'QQ号') {
            if (sw == true) {
                if ((app.globalData.user_form[0].edit == false) || (app.globalData.user_form[0].edit == undefined)) {
                    app.globalData.user_form[app.globalData.user_form.length] = {};
                    app.globalData.user_form[app.globalData.user_form.length - 1].item = 'number';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_name = 'QQ号';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_nec = true;
                } else if (app.globalData.user_form[0].edit == true) {
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name = 'QQ号';
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec = true;
                }
            } else if ((sw == false) || (sw == undefined)) {
                if ((app.globalData.user_form[0].edit == false) || (app.globalData.user_form[0].edit == undefined)) {
                    app.globalData.user_form[app.globalData.user_form.length] = {};
                    app.globalData.user_form[app.globalData.user_form.length - 1].item = 'number';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_name = 'QQ号';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_nec = false;
                } else if (app.globalData.user_form[0].edit == true) {
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name = 'QQ号';
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec = false;
                }
            }
        } else if (radio == '微信号') {
            if (sw == true) {
                if ((app.globalData.user_form[0].edit == false) || (app.globalData.user_form[0].edit == undefined)) {
                    app.globalData.user_form[app.globalData.user_form.length] = {};
                    app.globalData.user_form[app.globalData.user_form.length - 1].item = 'number';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_name = '微信号';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_nec = true;
                } else if (app.globalData.user_form[0].edit == true) {
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name = '微信号';
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec = true;
                }
            } else if ((sw == false) || (sw == undefined)) {
                if ((app.globalData.user_form[0].edit == false) || (app.globalData.user_form[0].edit == undefined)) {
                    app.globalData.user_form[app.globalData.user_form.length] = {};
                    app.globalData.user_form[app.globalData.user_form.length - 1].item = 'number';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_name = '微信号';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_nec = false;
                } else if (app.globalData.user_form[0].edit == true) {
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name = '微信号';
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec = false;
                }
            }
        } else if (radio == '电子邮件') {
            if (sw == true) {
                if ((app.globalData.user_form[0].edit == false) || (app.globalData.user_form[0].edit == undefined)) {
                    app.globalData.user_form[app.globalData.user_form.length] = {};
                    app.globalData.user_form[app.globalData.user_form.length - 1].item = 'number';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_name = '电子邮件';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_nec = true;
                } else if (app.globalData.user_form[0].edit == true) {
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name = '电子邮件';
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec = true;
                }
            } else if ((sw == false) || (sw == undefined)) {
                if ((app.globalData.user_form[0].edit == false) || (app.globalData.user_form[0].edit == undefined)) {
                    app.globalData.user_form[app.globalData.user_form.length] = {};
                    app.globalData.user_form[app.globalData.user_form.length - 1].item = 'number';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_name = '电子邮件';
                    app.globalData.user_form[app.globalData.user_form.length - 1].item_nec = false;
                } else if (app.globalData.user_form[0].edit == true) {
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_name = '电子邮件';
                    app.globalData.user_form[app.globalData.user_form[0].edit_num].item_nec = false;
                }
            }
        }
        //返回上一个页面
        wx.navigateBack({
            url: '../items'
        })
    } else {
        wx.showModal({
            title: '提示',
            content: '请至少选择一项',
            showCancel: 'false'
        })
    }
}
module.exports = saveNumber;